package com.xt.mes;

import com.xt.mes.config.IpAndPortUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.net.UnknownHostException;

@SpringBootApplication
public class MesApplication extends SpringBootServletInitializer implements WebMvcConfigurer {

    public static void main(String[] args) throws UnknownHostException {
        SpringApplication sa = new SpringApplication(MesApplication.class);
        Environment env = sa.run(args).getEnvironment();
        System.out.println("swagger的文档地址： "+IpAndPortUtil.getUrl(env)+"/doc.html ");
    }


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MesApplication.class);
    }

    /** * 重写addResourceHandlers，可以访问 http://localhost:port/doc.html  文档 * @param registry */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
